<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


class Main extends CI_Controller {

    public function index() {
        $this->load->model('PostsModel');

        $this->load->model('EventsModel');

        $template_data = array();
        $template_data['title'] = 'Thread';
        $template_data['scripts'] = array('post.js', 'post-tabs.js', 'jquery.placeholder.min.js', 'createpoll.js','event.js', 'fancy_box.js');

        $events = $this->EventsModel->getEvents();
        $posts = $this->PostsModel->getPosts(null);
        

        // create data array to send to the main view
        $view_data = array();
        $view_data['posts'] = $posts;
        $view_data['events'] = $events;

        $this->template->view('main', $view_data, $template_data);
    }


    public function vote() {
        $this->load->model('PollsModel');
        $option_id = trim($this->input->post('option_id'));
        if ($option_id == "") {
            return;
        }

        $user_id = $this->tank_auth->get_user_id();
        $this->PollsModel->registerVote($user_id, $option_id);
        redirect('/');
    }


}
?>